import * as mars3d from "mars3d";
import {
  Home,
  Local,
  PreviewOpen,
  AppSwitch,
  Forbid,
  Cube,
  MultiTriangular,
  Shovel,
  Close,
  MapDistance,
  Ruler,
  Texture,
  AutoHeightOne,
  Compass,
  DeleteKey,
  Mark,
  Label,
  Change,
  BringToFrontOne,
  Asterisk,
  Rectangle,
  Editor,
  Export,
  ClearFormat,
  Effects,
  LightRain,
  Snow,
  Fog,
  Halo,
  Brightness,
  DarkMode,
  Blackboard,
  HighLight,
  Config,
  LandSurveying,
  TwoTriangles,
  Sun,
  FlightAirflow,
  AddPicture,
  SwitchThemes,
  Agreement,
  TakeOff,
  KeyboardOne,
  RecentViewsSort,
  MoveInOne,
  ExclusiveGateway,
  CloseOne,
  LockOne,
  Box,
  MonitorOff,
  MapTwo,
  International,
  DatabaseForbid,
} from "@icon-park/svg";

const Cesium = mars3d.Cesium;

// 获取平台内置的右键菜单
export function getDefaultContextMenu(map) {
  const that = map.contextmenu;
  return [
    {
      text: () => {
        return map.getLangText("_查看此处坐标");
      },
      icon: Local({ theme: "outline", fill: "#fff", size: "18" }),
      show: function (e) {
        return Cesium.defined(e.cartesian);
      },
      callback: function (e) {
        // 经纬度
        const mpt = mars3d.LngLatPoint.fromCartesian(e.cartesian);
        const ptNew = mars3d.PointTrans.proj4Trans(
          [mpt.lng, mpt.lat],
          "EPSG:4326",
          mars3d.CRS.CGCS2000_GK_Zone_3
        );

        const inhtml = `
         经度:${mpt.lng}, 纬度:${mpt.lat}, 海拔:${mpt.alt}
        `;
        alert(inhtml);
        console.log(`${mpt.lng},${mpt.lat}`);
      },
    },
    {
      text: () => {
        return map.getLangText("_查看当前视角");
      },
      icon: PreviewOpen({ theme: "outline", fill: "#fff", size: "18" }),
      callback: function (e) {
        const mpt = JSON.stringify(map.getCameraView());
        console.log(mpt, map.getLangText("_当前视角信息"));
      },
    },
    {
      text: () => {
        return map.getLangText("_地形服务");
      },
      icon: International({ theme: "outline", fill: "#fff", size: "18" }),
      show: function (e) {
        return Cesium.defined(e.cartesian);
      },
      children: [
        {
          text: () => {
            return map.getLangText("_开启地形");
          },
          icon: MapTwo({ theme: "outline", fill: "#fff", size: "18" }),
          show: function (e) {
            return !map.hasTerrain;
          },
          callback: function (e) {
            map.hasTerrain = true;
          },
        },
        {
          text: () => {
            return map.getLangText("_关闭地形");
          },
          icon: CloseOne({ theme: "outline", fill: "#fff", size: "18" }),
          show: function (e) {
            return map.hasTerrain;
          },
          callback: function (e) {
            map.hasTerrain = false;
          },
        },
        {
          text: () => {
            return map.getLangText("_显示三角网");
          },
          icon: MultiTriangular({ theme: "outline", fill: "#fff", size: "18" }),
          show: function (e) {
            return !map.scene.globe._surface.tileProvider._debug.wireframe;
          },
          callback: function (e) {
            map.scene.globe._surface.tileProvider._debug.wireframe = true;
          },
        },
        {
          text: () => {
            return map.getLangText("_关闭三角网");
          },
          icon: CloseOne({ theme: "outline", fill: "#fff", size: "18" }),
          show: function (e) {
            return map.scene.globe._surface.tileProvider._debug.wireframe;
          },
          callback: function (e) {
            map.scene.globe._surface.tileProvider._debug.wireframe = false;
          },
        },
      ],
    },
    {
      text: () => {
        return map.getLangText("_图上量算");
      },
      icon: Ruler({ theme: "outline", fill: "#fff", size: "18" }),
      children: [
        {
          text: () => {
            return map.getLangText("_距离");
          },
          icon: MapDistance({ theme: "outline", fill: "#fff", size: "18" }),
          callback: function (e) {
            if (!that.measure) {
              that.measure = new mars3d.thing.Measure();
              map.addThing(that.measure);
            }
            that.measure.distance();
          },
        },
        {
          text: () => {
            return map.getLangText("_面积");
          },
          icon: Texture({ theme: "outline", fill: "#fff", size: "18" }),
          callback: function (e) {
            if (!that.measure) {
              that.measure = new mars3d.thing.Measure();
              map.addThing(that.measure);
            }
            that.measure.area();
          },
        },
        {
          text: () => {
            return map.getLangText("_高度差");
          },
          icon: AutoHeightOne({ theme: "outline", fill: "#fff", size: "18" }),
          callback: function (e) {
            if (!that.measure) {
              that.measure = new mars3d.thing.Measure();
              map.addThing(that.measure);
            }
            that.measure.heightTriangle();
          },
        },
        {
          text: () => {
            return map.getLangText("_角度");
          },
          icon: Compass({ theme: "outline", fill: "#fff", size: "18" }),
          callback: function (e) {
            if (!that.measure) {
              that.measure = new mars3d.thing.Measure();
              map.addThing(that.measure);
            }
            that.measure.angle();
          },
        },
        {
          text: () => {
            return map.getLangText("_删除测量");
          },
          icon: DeleteKey({ theme: "outline", fill: "#fff", size: "18" }),
          show: function (e) {
            return that.measure && that.measure.hasMeasure;
          },
          callback: function (e) {
            if (that.measure) {
              that.measure.clear();
            }
          },
        },
      ],
    },
  ];
}
